package com.deer.wms.ASN.manage.web;

import com.deer.wms.ASN.manage.constant.AsnManageConstant;
import com.deer.wms.ASN.manage.model.pack.PackBillBO;
import com.deer.wms.ASN.manage.service.PackBillService;
import com.deer.wms.intercept.annotation.User;
import com.deer.wms.intercept.common.data.CurrentUser;
import com.deer.wms.project.root.core.result.Result;
import com.deer.wms.project.root.util.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Date;
import java.util.List;

/**
 * @author : wei
 * @since : 2021-10-27 16:27:10
 **/
@Api(description = "组托拆托接口")
@RestController
@RequestMapping("/pack")
public class PackBillController {

    @Autowired
    private PackBillService packBillService;

    @ApiOperation(value = "组托拆托")
    @GetMapping("/pack")
    public Result pack(List<PackBillBO> packBillBOs, @ApiIgnore @User CurrentUser currentUser){

        //整理数据
        for (PackBillBO bo : packBillBOs) {
            bo.setPackUserId(currentUser.getUserId());
            bo.setPackUserName(currentUser.getUserName());
            bo.setPackTime(new Date());
            //判断组托拆托类型
            if (StringUtils.isEmpty(bo.getTargetLpn())) {
                bo.setOperType(AsnManageConstant.PACK_OPER_TYPE_OUT);
            } else if (StringUtils.isEmpty(bo.getSourceLpn())) {
                bo.setOperType(AsnManageConstant.PACK_OPER_TYPE_IN);
            } else {
                bo.setOperType(AsnManageConstant.PACK_OPER_TYPE_IO);
            }
        }

        packBillService.pack(packBillBOs);
        return null;
    }


}
